home *** CD-ROM | disk | FTP | other *** search
- /**
- * NOANSI.C TSR to allow enabling or disabling of ANSI.SYS.
- *
- * The command line format is as follows:
- *
- * noansi [-r]
- *
- * NOANSI is a self-removing TSR. If it is invoked with no arguments, it
- * installs itself (if not already installed). The -r option will cause
- * it to remove itself if it is installed.
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1989
- *
- **/
-
-
- #include <dos.h>
- #include <stdio.h>
-
- #include <binterv.h>
- #include <bintrupt.h>
- #include <bkeybrd.h>
- #include <bkeys.h>
- #include <butil.h>
- #include <ctype.h>
-
- /* The declaration of the intervention function. */
- /* It will be called when the hot key is pressed. */
- void keyhandler(IV_EVENT *);
-
- #define TRUE 1
- #define FALSE 0
- #define NUL '\0'
-
- #define STKSIZE 2000
- #define OK 0
- #define FALL_OUT 101
-
- #define NOT_FOUND 1
- #define ERROR_DISABLING 2
- #define ERROR_REMOVING 3
- #define ALREADY_INSTALLED 4
- #define NO_ANSI_INSTALLED 5
-
- /* Signature for this version of CTRLANSI. */
- #define NOANSI_SIGN "NOANSI 03/31/89"
-
- /* Allocation of stack space for the intervention */
- /* scheduler and user function. */
- char schedstk [STKSIZE];
-
- /* This is the data structure to pass to the */
- /* scheduler so that it will give control every */
- /* time ALT A is pressed. */
- IV_KEY keytab [] =
- {
- {KB_C_A_A, KB_S_A_A, IV_KY_SERVICE}, /* Activate ANSI */
- {KB_C_A_D, KB_S_A_D, IV_KY_SERVICE} /* Disable ANSI */
- };
-
- #define k(c) kbscanof(c)
-
- /* Internal functions -- install and remove */
- /* intervention function. */
- int install_iv(void);
- int remove_iv(void);
-
- void main(int, char **);
-
- void main(argc, argv)
- int argc;
- char *argv[];
- {
- if (argc == 1)
- exit(install_iv());
-
- if ((argc == 2) && ((argv[1][0] == '-') || (argv[1][0] == '/')))
- if (toupper(argv [1][1]) == 'R')
- exit (remove_iv());
-
- printf ("usage: ctrlansi [-r]\n");
- exit (0);
- }
-
-
-
- /**
- *
- * Name INSTALL_IV -- Install interrupt vectors for NOANSI,
- * then terminate and stay resident.
- *
- * Synopsis ret = install_iv();
- *
- * int ret Return code from IVINSTAL if an
- * error condition was encountered.
- *
- * Description This function installs NOANSI if another copy
- * is not already installed, and ANSI.SYS is installed.
- *
- * Returns ret ALREADY_INSTALLED (4)
- * A copy of CTRLANSI is already installed.
- * NO_ANSI_INSTALLED (5)
- * ANSI.SYS is not installed.
- * FALL_OUT (101)
- * ISRESEXT() failed.
- *
- **/
-
- int install_iv()
- {
- int ercode;
- IV_VECTORS vecs;
-
- /* Check to see if CTRLANSI already installed. */
- ivvecs(IV_RETVEC, &vecs);
- if (ivsense(&vecs, NOANSI_SIGN) != FARNIL)
- {
- puts ("NOANSI already installed.");
- return(ALREADY_INSTALLED);
- }
-
- /* Check to see if ANSI.SYS is installed. */
- if (UT_ANS_ABSENT == utansi(UT_ANS_DETECT))
- {
- puts("ANSI.SYS is not installed.\n");
- return(NO_ANSI_INSTALLED);
- }
-
- /* Install the intervention routine. */
- ercode = ivinstal(keyhandler, NOANSI_SIGN, schedstk, STKSIZE,
- keytab, sizeof(keytab) / sizeof(IV_KEY),
- NIL, 0,
- /* utansi() uses DOS functions, including 1-12. */
- IV_DOS_NEED | IV_DKEY_NEED | IV_NO_FLOAT_NEED);
- if (ercode != 0)
- {
- printf("IVINSTAL error %d.\n", ercode);
- return(ercode);
- }
-
- /* Terminate and stay resident. */
- isresext(OK);
-
- /* Should never get here. */
- return(FALL_OUT);
- }
-
-
-
- /**
- *
- * Name REMOVE_IV -- Remove a previously installed copy of
- * NOANSI.
- *
- * Synopsis ret = remove_iv();
- *
- * int ret Return code.
- * NO_ERROR (0)-
- * No error encountered.
- * NOT_FOUND (1)-
- * NOANSI not found.
- * ERROR_DISABLING (2)-
- * NOANSI could not be disabled.
- * This error should *never* be
- * seen.
- * ERROR_REMOVING (3)--
- * NOANSI could not be removed (most
- * likely overwritten MALLOC
- * pointers).
- *
- * Description This function removes a currently-active copy of NOANSI
- * from memory, restoring interrupt vectors and freeing
- * memory in the process.
- *
- * Returns ret (nonzero if error--see above).
- *
- **/
-
- int remove_iv()
- {
- IV_VECTORS vecs;
- IV_CTRL far *pivctrl;
-
- /* Check to see if NOANSI installed. */
- ivvecs(IV_RETVEC, &vecs);
- if ((pivctrl = ivsense(&vecs, NOANSI_SIGN)) == FARNIL)
- {
- puts("NOANSI not found.");
- return(NOT_FOUND);
- }
-
- /* Make sure to leave ANSI.SYS enabled on exit. */
- utansi(UT_ANS_ENABLE);
-
- if (ivdisabl(pivctrl))
- {
- puts("Error disabling NOANSI.");
- return(ERROR_DISABLING);
- }
-
- if (isremove(pivctrl->psp))
- {
- puts("Error removing NOANSI.");
- return(ERROR_REMOVING);
- }
-
- return(0);
- }
-
-
-
- /**
- *
- * Name KEYHANDLER -- Handle hot key events.
- *
- * Synopsis (To be called only by intervention code scheduler)
- *
- * keyhandler(pevent);
- *
- * IV_EVENT *pevent Pointer to intervention event
- * structure. The structure
- * contains the hot key which
- * was detected (if any), as
- * well as other data.
- *
- * Description This function accepts control from the scheduler
- * every time a defined hot key is pressed. ALT-A will
- * disable ANSI.SYS; ALT-D will disable it.
- *
- * Returns None.
- *
- **/
-
- void keyhandler(pevent)
- IV_EVENT *pevent;
- {
- int error;
-
- /* Do a key action, if one exists. */
- switch (pevent->key.action)
- {
- /* If the user typed a "service" key, perform the */
- /* appropriate action. */
- case IV_KY_SERVICE:
- if (pevent->key.keycode == KB_S_A_A)
- {
- error = utansi(UT_ANS_ENABLE);
- if (error != UT_ANS_ENABLE)
- printf("NOANSI: Error enabling ANSI.SYS.\n");
- }
- else
- {
- error = utansi(UT_ANS_DISABLE);
- if (error != UT_ANS_DISABLE)
- printf("NOANSI: Error disabling ANSI.SYS.\n");
- }
- break;
- }
-
- }